package com.sinoglobal.dumping.util;

import android.util.Log;

import java.security.MessageDigest;

/**
 * MD5工具
 */
public class Dumpling_Md5Util {
    private static MessageDigest md5;
    static{
        try {
            md5=MessageDigest.getInstance("MD5");
        } catch (Exception e) {
            Log.e("md5",e.getMessage());
        }
    }

    public static String string2Md5(String str){
        byte[] bs=md5.digest(str.getBytes());
        StringBuilder stringBuilder=new StringBuilder(40);
        for (byte x:bs) {

            if ((x&0xff)>>4==0) {
                stringBuilder.append("0").append(Integer.toHexString(x&0xff));
            } else {
                stringBuilder.append(Integer.toHexString(x&0xff));
            }
        }
        return stringBuilder.toString();
    }
}
